package com.nstar.helloworld.view
{
	import mx.core.Application;
	import mx.events.FlexEvent;
	import com.nstar.helloworld.controller.Controller;
	import com.nstar.helloworld.mxml.QueryView;
	import com.nstar.base.util.Logger;
	import com.nstar.helloworld.mxml.WelcomeView;
	import mx.controls.Button;
	import flash.events.MouseEvent;
	import com.nstar.helloworld.model.Model;
	import com.nstar.base.controls.StatusBar;
	import mx.containers.ViewStack;
	import flash.events.Event;
	import com.adobe.ac.mxeffects.DistortionConstants;
	import com.adobe.ac.mxeffects.CubeRotate;
	import com.nstar.base.controls.Header;
	import com.nstar.base.controls.ButtonAssets;
	import com.nstar.helloworld.mxml.TipView;
	import mx.managers.PopUpManager;
	import mx.effects.Move;
	import mx.collections.ArrayCollection;

	public class HelloWorldApp extends Application
	{
		//视图定义
		public var queryView:QueryView ;
		public var welcomeView:WelcomeView ;
		public var vsMain:ViewStack;
		public var status:StatusBar;
		public var header:Header;
		
		var login_state_no:String = "用户状态 - 未登录";
		//日志
		var logger:Logger = Logger.getInstance();
		//模型
		var model:Model = Model.getInstance();
		
		public var test:Button ;
		
		public var flipIn:CubeRotate = new CubeRotate();
		public var flipBack:CubeRotate = new CubeRotate();		 
		[Bindable]
		public var effect:CubeRotate = new CubeRotate();		
		
		
		public function HelloWorldApp()
		{
			//TODO: implement function
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE,init);
		}
		
		function init(event:FlexEvent):void{
			Controller.getInstance().registerApp(this);
			model.mainApp = this;
			
			header.addLink("日志",showLogger,false,20,ButtonAssets.folderPageIcon);
			header.addLink("测试",testHandler,false,20,ButtonAssets.tips);
			
			status.addPanel(150);
			status.showMsgText(login_state_no,1);
			
			
			flipIn.direction = DistortionConstants.RIGHT;
			flipIn.duration = 1500;
			flipIn.siblings = new Array();
			
			flipBack.direction = DistortionConstants.LEFT;
			flipBack.duration = 1500;
			flipBack.siblings = new Array();	
			
			welcomeView.addEventListener(Event.SELECT,selectHandler);	
		}
		
		//右转效果
		function flipInHandler(index:int=0):void{
			flipIn.target = vsMain.getChildAt(index + 1);
			flipIn.siblings = [vsMain.selectedChild];
			effect = flipIn; 
		}
		//左转效果
		function flipBackHandler(index:int=1):void{
			flipBack.target = vsMain.getChildAt(index - 1);	
			flipBack.siblings = [vsMain.selectedChild];	
			effect = flipBack;
		}	
			
		function selectHandler(event:Event):void{
			vsMain.selectedIndex = 1;
		}
		
		//显示日志信息
		function showLogger(event:MouseEvent):void{
			logger.showLogView("日志信息");
		}
		
		function testHandler(event:MouseEvent):void{
			var tv:TipView = TipView(PopUpManager.createPopUp(this,TipView));
			tv.x = 0;
			tv.y = 200;
			var move:Move = new Move();
			move.target = tv;
			move.xTo = 400;
			move.yTo = 200;
			move.play();
		}
		

	}
}